//index.js
//获取应用实例
const app = getApp();
const commonService = require('../../service/common.js');

Page({
  data: {
    title:"消息",
    list:[],
    queryParams: {
      page: 1,
      num: 10
    },
    isLast: false
  },
  onLoad: function () {
  },
  onShow: function(){
    if(app.checkLogin()){
      this.data.list = "";
      this.getContentList();
    };
  },
  getContentList() {
    console.log(app.globalData);
    let unionId = app.globalData.userinfo.unionId;
    let d = {
      unionId,
      ...this.data.queryParams
    }
    commonService.getMessageList(d).then(res => {
      if (res.resCode == 0) {
        if (!res.object.length) {
          this.setData({
            isLast: true
          });
          return false;
        }
        this.setData({
          list: [
            ...this.data.list,
            ...res.object
          ]
        });
      }
    })
  },
  onReachBottom() {
    if (this.data.isLast) return false;
    this.setData({
      queryParams: {
        page: ++this.data.queryParams.page,
        num: 10
      }
    })
    this.getContentList();
  }
})
